package sis.studentinfotest;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-07-24 20:02
 * @notify
 * @version 1.0
 */

import junit.framework.TestCase;
import sis.studentinfo.Performance;

import static java.lang.Float.NaN;

public class PerformanceTest extends TestCase {
    private static final double tolerance = 0.005;

    public void testAverage() {
        Performance performance = new Performance();
        performance.setNumberOfTests(4);
        performance.set(0, 98);
        performance.set(1, 92);
        performance.set(2, 81);
        performance.set(3, 72);
        assertEquals(92, performance.get(1));
        assertEquals(85.75, performance.average(), tolerance);
    }

    public void testInitialization() {
        Performance performance = new Performance();
        performance.setScores(75, 72, 90, 60);
        assertEquals(74.25, performance.average(), tolerance);
    }

    public void testAverageForNoScores() {
        Performance performance = new Performance();
        assertEquals(0.0, performance.average());
    }

    public void testNaN() {
        assertFalse(Double.NaN == Double.NaN);
        assertFalse(Double.NaN == 1);
    }

    public void testDouble() {
        final float tolerance = 0.5f;
        final float x = 1f;

        assertEquals(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY * 100, tolerance);

        assertEquals(Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY * -1, tolerance);

        byte b = Byte.MAX_VALUE;
        assertEquals(Byte.MAX_VALUE + 1, b + 1);

        assertEquals(Byte.MIN_VALUE,b+=1);

    }
}
